//
//  BKMyOrderDiscountView.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/14.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderDiscountView.h"
#import "BK_OD_Tool.h"



#import "BK_OD_Color.h"




@implementation BKMyOrderDiscountView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _view_back = [[UIView alloc]initWithFrame:self.frame];
        _view_back.backgroundColor  = ThemeBackgroundColor;
        [self addSubview:_view_back];
    }
    
    return self;
}

-(UILabel *) InitLabel:(NSString *)text Font:(UIFont *)font
{
    UILabel *label = [UILabel new];
    label.text = [NSString stringWithFormat:@"%@",text];
    label.textColor =  kOrderBlack1;
    label.font = font;
    return label;
}

-(void)setModel:(BK_My_DetailOrder_Model *)model{
 
    NSMutableArray *array = [NSMutableArray array];
    for (BK_My_DetailOrder_payAmountDetail_Model *list in model.payAmountDetail) {
        if (![list.itemAmountStr isEqualToString:@"0.00"]) {
            [array addObject:list];
            
        }
    }
    
    for(BK_My_DetailOrder_payAmountDetail_Model*listModel  in array)
    {
        UILabel *leftLabel = [self InitLabel:listModel.itemName Font:[UIFont systemFontOfSize:14]];
        [self addSubview:leftLabel];
        [self SetLeftControlsConstraints:leftLabel];
        UILabel *rightLabel = [self InitLabel:listModel.itemAmountStr Font:[UIFont systemFontOfSize:14]];
        [self addSubview:rightLabel];
        [self SetRightControlsConstraints:rightLabel LeftControls:leftLabel];
    }
    
}
-(void) SetLeftControlsConstraints:(UILabel *)label
{
    NSArray *array = [self subviews];
    NSMutableArray *views = [NSMutableArray  array];
    for (UIView *view in array) {
        if ([view isKindOfClass:[UILabel class]]) {
            [views addObject:view];
            
        }
    }
    [label mas_makeConstraints:^(MASConstraintMaker *make)
     {
         NSInteger number = views.count/2;
         make.top.mas_equalTo(self.view_back.mas_top).offset(number>0?30*number+10:10);
         make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
         make.height.mas_equalTo(30);
     }];
}

-(void) SetRightControlsConstraints:(UILabel *)label LeftControls:(UILabel *)control
{
    float h = ScreenWidth -ApplicationBackGauge;
    [label mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.right.mas_equalTo(self.mas_right).offset(h);
         make.centerY.mas_equalTo(control.mas_centerY);
         make.height.mas_equalTo(30);
     }];
}




@end
